{% extends 'base.html' %}

{% block title %}{{ product.name }} - 产品详情{% endblock %}

{% block content %}
<div class="row">
    <div class="col-12">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h1>产品详情</h1>
            <a href="{{ url_for('index') }}" class="btn btn-secondary">返回列表</a>
        </div>

        <div class="card mb-4">
            <div class="card-header">
                <h5 class="card-title mb-0">基本信息</h5>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-3">
                        <p class="mb-1"><strong>产品名称：</strong></p>
                        <p class="text-muted">{{ product.name }}</p>
                    </div>
                    <div class="col-md-3">
                        <p class="mb-1"><strong>产品类别：</strong></p>
                        <p class="text-muted">{{ product.category }}</p>
                    </div>
                    <div class="col-md-6">
                        <p class="mb-1"><strong>规格：</strong></p>
                        <p class="text-muted">{{ product.specification }}</p>
                    </div>
                </div>
            </div>
        </div>

        <div class="card mb-4">
            <div class="card-header">
                <h5 class="card-title mb-0">材料清单</h5>
            </div>
            <div class="card-body">
                {% if product.materials %}
                <div class="table-responsive">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>材料名称</th>
                                <th>规格</th>
                                <th>品牌</th>
                                <th>型号</th>
                                <th>用量</th>
                                <th>单价</th>
                                <th>小计</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for pm in product.materials %}
                            <tr>
                                <td>{{ pm.material.name }}</td>
                                <td>{{ pm.material.specification }}</td>
                                <td>{{ pm.material.brand }}</td>
                                <td>{{ pm.material.model }}</td>
                                <td>{{ pm.quantity }}{{ pm.material.unit }}</td>
                                <td>{{ "%.2f"|format(pm.material.price) }}</td>
                                <td>{{ "%.2f"|format(pm.subtotal) }}</td>
                            </tr>
                            {% endfor %}
                        </tbody>
                        <tfoot>
                            <tr>
                                <td colspan="6" class="text-end"><strong>材料成本合计：</strong></td>
                                <td><strong>{{ "%.2f"|format(product.material_cost) }}</strong></td>
                            </tr>
                        </tfoot>
                    </table>
                </div>
                {% else %}
                <p class="text-muted">暂无材料数据</p>
                {% endif %}
            </div>
        </div>

        <div class="card mb-4">
            <div class="card-header">
                <h5 class="card-title mb-0">工序清单</h5>
            </div>
            <div class="card-body">
                {% if product.processes %}
                <div class="table-responsive">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>工序名称</th>
                                <th>工序描述</th>
                                <th>数量</th>
                                <th>单价</th>
                                <th>小计</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for pp in product.processes %}
                            <tr>
                                <td>{{ pp.process.name }}</td>
                                <td>{{ pp.process.description }}</td>
                                <td>{{ pp.quantity }}{{ pp.process.unit }}</td>
                                <td>{{ "%.2f"|format(pp.process.price) }}</td>
                                <td>{{ "%.2f"|format(pp.subtotal) }}</td>
                            </tr>
                            {% endfor %}
                        </tbody>
                        <tfoot>
                            <tr>
                                <td colspan="4" class="text-end"><strong>人工成本合计：</strong></td>
                                <td><strong>{{ "%.2f"|format(product.labor_cost) }}</strong></td>
                            </tr>
                        </tfoot>
                    </table>
                </div>
                {% else %}
                <p class="text-muted">暂无工序数据</p>
                {% endif %}
            </div>
        </div>

        <div class="card">
            <div class="card-header bg-primary text-white">
                <h5 class="card-title mb-0">成本汇总</h5>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-4">
                        <h6>材料成本</h6>
                        <h4>{{ "%.2f"|format(product.material_cost) }}</h4>
                    </div>
                    <div class="col-md-4">
                        <h6>人工成本</h6>
                        <h4>{{ "%.2f"|format(product.labor_cost) }}</h4>
                    </div>
                    <div class="col-md-4">
                        <h6>总价</h6>
                        <h4 class="text-primary">{{ "%.2f"|format(product.total_price) }}</h4>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}